OPEN

Syntax: OPEN #channel, device   channel=0..32767
    or: OPEN #channel, device, type  (Minerva v1.80+ only)
Location: QL ROM, Toolkit II

This is the general command used to open a channel to a device for input and/or output, so that data can be read from and written to the specified device.

The channel number can be any integer greater than or equal to zero.

You then need to specify the device name, such as:

OPEN #3,scr_448x200
OPEN #4,'flp1_test'

After the channel has been OPENed, if a program needs to access that device in the future, it can do so by passing that channel number to the relevant keyword.

If you have Toolkit II installed OPEN supports sub-directories and default devices when used on drives.  OPEN will look in the data directory (see DATAD$) for the given file if no device is specified. 

NOTE:
Any attempt to open more than one channel to a serial port will report the error 'in use', unless you are using the ST/QL Emulator which allows more than one input channel to be opened to a serial port.

MINERVA NOTES:
On v1.80 (and later), a third parameter is supported on this command which can be used to specify the 'open type'. This is only of any use on drives and pipes.

Drives
Open type Effect
0         Open existing file for
          exclusive use (OPEN)
1         Open existing file for
          shared use (OPEN_IN)
2         Open new file (OPEN_NEW)
3         Open file and overwrite
          if already exists (OPEN_OVER)
4         Open directory file
          (OPEN_DIR)

Pipes:
The extra parameter supplies the QDOS channel number of the source end of the pipe. This is therefore only of use when opening the 'read' end of the pipe. This gets around the necessity for commands like QLINK. For example these two lines are the same:

OPEN#4,'pipe_4000': QLINK#4 TO #3 
OPEN#4, 'pipe_4000': pipe_id=PEEK_W (\48\4*40+2) : OPEN#3, 'pipe_', pipe_id

CROSS-REFERENCE:
Opened channels are closed with CLOSE and can be listed with CHANNELS.  
FOPEN is the same as OPEN except it works as a function and  OPEN_IN / FOP_IN open a device for input only.  
OPEN_DIR (FOP_DIR) opens a directory (or a sub-directory on level-2 drivers).
Also see OPEN_NEW, FOP_OVER, TTEOPEN and FILE_OPEN.
NEWCHAN% can be quite useful when OPENing channels.
